package jsp.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jpa.entities.Employee;
import jpa.entities.Project;
import jsp.classes.Session;

/**
 * @author Remco Haszing
 * @author Aymeric Blok
 */
public class RemoveUser extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            Session session = (Session) request.getSession(true).getAttribute("user");
            
            Integer id = null;
            Integer pid = null;
            
            for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
                String k = entry.getKey();
                String[] v = entry.getValue();
                if (k.equals("id")) {
                    String idstring = v[0];
                    id = Integer.parseInt(idstring);
                } else if (k.equals("pid")) {
                    String pidstring = v[0];
                    pid = Integer.parseInt(pidstring);
                }
            }
            
            Project proj = session.findProjectById(pid);
            
            Employee emp1 = session.findEmployeeById(id);
            emp1.removeProject(proj);
            
            response.getWriter().print("true");
        } catch (Exception e) {
            response.getWriter().print("false");
        }
    }
}
